package com.efei.test.jdbc.web;


import com.efei.test.jdbc.dao.UserInfoRepository;
import com.efei.test.jdbc.entity.UserInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/jdbc")
public class JdbcTestController {

    @Autowired
    private UserInfoRepository userInfoRepository;

    @GetMapping("/testGet")
    public void testGet(){
        List<UserInfoEntity> userInfoList = userInfoRepository.findByName("刘亦飞");
        System.out.println(userInfoList);
    }

    @GetMapping("/testInsert")
    public void testInsert(){
//        String ss[] = "贡晨风,简元英,于幼珊,宓琬琰,吕琰琬,孙沁媛,乔倩语,那娟娣,芮白安,余旭妍,屠刖颖,暨怀慕,漕梧桐,慎思凡,邓畅畅,梁玲娇,范欣彤,黎智菱,容雨琼,乔明智,冯元风,堵丽玉,廖芷茹,徐琼诗,赖艾达,于寻芹,朱念寒,文秉文,庾梦曼,甘嘉音,符暄妍,红悦媛,牛嘉懿,蓟白晴,江紫槐,燕诗蕊,江诗兰,毋碧曼,石以柳,逢静淑,甄晏静,终妙意,闻思美,金布衣,相腊梅,钭问香,牛春雪,吕清宁,班林帆,郜智敏,鄂思萱,董芷秀,从菱凡,龚春晖,谭梦玉,曾雯琴,夏兰泽,訾绿柏,郜春桃,鱼小妍,焦问筠,韶晨希,通靖易,鱼琳敏,宋韶容,于碧彤,武悦和,金哲妍,仰生文,段夜蓉,董希月,陆许暖,钟臻晰,师代曼,冯妙颜,步芳蔼,雍寻菱,贺蕴秀,汤灵薇,索皓月,梁傲霜,晏灵松,蔚念露,濮惠芳,禄若烟,红桃尐,习偌丝,毋喜悦,叶玉琲,扶语薇,车曼青,连元灵,孙启颜,赖华芝,高沛珊,怀新雪,卓以山,吕寒梅,钟婉清,汲丽莉,范嫦娥,班半梦,籍诗珊,谢妍晨,弓悦宜,雍凝梦,戴一凡,班玉珂,菱映天,蒲孤丹,璩艾玲,怀梓云,暨韦曲,莘以山,殳夏柳,任晴雪,周梓馨,贡沛芹,祖若英,钟俏美,邹纯雪,逢艳蕙,任葛菲,双丰熙,莘水晶,农云梦,谷姣丽,吴美如,赖修美,步秀杰,訾婉柔,慎博丽,冀灵溪,曹蔚星,蔡梦琪,弓以蕊,红梓琬,方流逸,松甘雨,杨秀媛,文恨寒,晃华月,武小宸,巢春晓,广馨兰,牛黛娥,蒙韶华,桂怡可,菱安筠,燕苏娟,常易烟,阎忆安,终如风,宓淑贤,周丽珠,红涵韵,瞿泽琴,范卿蓉,廖婉燕,班泯熙,慕悠逸,苍若芳,刘雁芙,訾夏菡,富水卉,车芳馥,顾佳洁,阙素华,堵千凝,贾瑜英,文菊月,贺燕平,乜荌荌,谷春芳,桂紫真,黄安波,孟筠心,禄忆香,充朝雨,宦兰七,温宇丞,姚彩红,钟雅柔,邵芸溪,浦慧英,融米莱,党珠雨,董芮静,殳淼淼,韶问雁,景瑶瑾,冀幻莲,菱晴波,伊寻菱,蔡璇玑,宓从南,史怡金,毋平安,关梓婷,戌沙羽"
//                .split(",");
//        List<UserInfoEntity> list = new ArrayList<UserInfoEntity>();
//        for(int i=0;i<ss.length;i++){
//            UserInfoEntity info = new UserInfoEntity();
//            info.setName(ss[i]);
//            info.setSex(i%2);
//            info.setAge(new Random().nextInt(100));
//            info.setCreateTime(Timestamp.valueOf(LocalDateTime.now()));
//            info.setUpdateTime(Timestamp.valueOf(LocalDateTime.now()));
//            list.add(info);
//        }
//        userInfoRepository.saveAll(list);


    }
    @GetMapping("/testPage")
    public Page<UserInfoEntity> testInsert(@RequestParam  Integer page, @RequestParam Integer size){
        Pageable pageable = PageRequest.of(page, size);
        Page<UserInfoEntity> all = userInfoRepository.findAll(pageable);
        //Page<UserInfoEntity> all = userInfoRepository.findByAgeAfterOrderByIdDesc(10L,pageable);
        return all;
    }

}
